﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.Project;
using System.IO;
using Microsoft.VisualStudio;
using System.ComponentModel.Composition;

namespace PSLib.WOWAddon.Base
{
	/// <summary>
	/// The ProjectNode base class handles the following tasks of project creation:
	/// - Copies the project template file, SimpleProject.myproj, to the new project folder. The copy is renamed according to the name that is entered in the New Project dialog box. The ProjectGuid property value is replaced by a new GUID.
	/// - Traverses the MSBuild elements of the project template file, SimpleProject.myproj, and looks for Compile elements. For each Compile target file, copies the file to the new project folder.
	/// The derived ProjectNode class handles these tasks:
	/// - Enables icons for project and file nodes in Solution Explorer to be created or selected.
	/// - Enables additional project template parameter substitutions to be specified.
	/// </summary>
	public class WOWAddonProjectNode : ProjectNode
    {
		public WOWAddonProjectNode(ProjectPackage package)
        {
            this.package = package;
        }

		#region ProjectNode overrides

		/// <summary>
		/// Returns the project factory GUID.
		/// </summary>
        public override Guid ProjectGuid
        {
            get { return GuidList.guidProjectFactory; }
        }

        /// <summary>
		/// Returns the localized name of the project type.
        /// </summary>
		public override string ProjectType
        {
            get { return "ProjectType"; }
        }

		/// <summary>
		/// Method replaces template argument and copies selected files from the template folder to the destination project.
		/// </summary>
		/// <param name="source">Source filename.</param>
		/// <param name="target">Target filename.</param>
        public override void AddFileFromTemplate(string source, string target)
        {
			string nameSpace = this.FileTemplateProcessor.GetFileNamespace(target, this);
			string className = Path.GetFileNameWithoutExtension(target);

			this.FileTemplateProcessor.AddReplace("$nameSpace$", nameSpace);
			this.FileTemplateProcessor.AddReplace("$className$", className);

			this.FileTemplateProcessor.UntokenFile(source, target);
			this.FileTemplateProcessor.Reset();
        }
		/// <summary>
		/// Returns propery page Type IDs
		/// </summary>
		/// <returns></returns>
		protected override Guid[] GetConfigurationIndependentPropertyPages()
		{
			Guid[] result = new Guid[1];
			result[0] = typeof(GeneralPropertyPage).GUID;
			return result;
		}

		protected override Guid[] GetPriorityProjectDesignerPages()
		{
			Guid[] result = new Guid[1];
			result[0] = typeof(GeneralPropertyPage).GUID;
			return result;
		}
		/// <summary>
		/// Overriding default config provider
		/// </summary>
		/// <returns></returns>
		protected override ConfigProvider CreateConfigProvider()
		{
			return new WOWAddonProjectConfigProvider(this);
		}

		#region Prevent NET references processing

		protected override ReferenceContainerNode CreateReferenceContainerNode()
		{
			//Prevent default references node.
			return null;
		}

		public override int AddProjectReference()
		{
			return VSConstants.S_OK;
		}

		protected internal override int AddWebReference()
		{
			return VSConstants.S_OK;
		}

		#endregion

		public override FileNode CreateFileNode(ProjectElement item)
		{
			return new WOWAddonProjectFileNode(this,item);
		}

		#endregion

		private ProjectPackage package;
    }
}
